package com.rec.smile.chemical.controller;

import com.rec.smile.chemical.bo.User;
import com.rec.smile.chemical.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * Created by Administrator on 2016/6/1.
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/list0")
    @ResponseBody
    public List<User> list(){
        return userMapper.selectUsers(0,10);
    }

    @RequestMapping("/list")
    @ResponseBody
    public ModelAndView list4View(){
        List<User> users = userMapper.selectUsers(0,10);
        return new ModelAndView("list", "messages", users);
    }

    @RequestMapping("/{id}/info")
    @ResponseBody
    public User findUser(@PathVariable("id") Integer id){
        return userMapper.selectByPrimaryKey(id);
    }
}
